home *** CD-ROM | disk | FTP | other *** search
- /*
- ** PGP5GUI - A GUI using Magic User Interface v3.8
- **
- ** Copyright 23-JUNE-1998 by Stefan Zakarias, All Rights Reserved.
- **
- ** This source code is released as FREEWARE - Use it for whatever you like,
- ** as long as NO financial reward is gained by you for such usage.
- **
- ** If you use any parts of the this source code for anything, give ME credit
- ** wherever credit is due, please ;-)
- */
-
-
- #ifndef MAKE_ID
- #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
- #endif
-
- /* Types */
- #include <exec/types.h>
-
- /* Libraries */
- #include <libraries/mui.h>
- #include <exec/memory.h>
-
- /* Prototypes */
- #ifdef __GNUC__
- #include <clib/muimaster_protos.h>
- #include <proto/alib.h>
- #endif
-
- #include <proto/muimaster.h>
- #include <clib/alib_protos.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
-
- /* Ansi */
- #include <string.h>
-
- #include "PGP5GUI.h"
- #include "SelPGPKeyGUI.h"
-
- extern char *keystable[];
- extern char *ReadyMSG;
-
- /*
- ** A function used by the "listview" gadget to split a line
- ** into columns to be displayed by the "listview" gadget.
- */
- #ifdef __SASC
- #define REG(x) register __ ## x
-
- static __saveds __asm void
- DisplayLI_TextFunc(REG(a0) struct Hook *hook, REG(a2) char **array, REG(a1) char *str)
- {
- #endif
- #ifdef __GNUC__
- static void
- DisplayLI_TextFunc(void)
- {
- register char **a2 __asm("a2"); char **array = a2;
- register char *a1 __asm("a1"); char *str = a1;
- register struct Hook *a0 __asm("a0"); struct Hook *hook = a0;
- #endif
-
- static char algo[ALGO_SIZE];
- static char keyID[KEYID_SIZE];
- static char created[CREATED_SIZE];
- static char userID[USERID_SIZE];
- static char buffer[BUFFER_SIZE];
-
- char *indptr;
-
- /* Is this a string with text in it? */
- if (str)
- {
- /*
- ** We've got text in the string...
- ** Break up the line and store it as columns.
- */
-
- /* Get a copy of 'str' into 'buffer' */
- strcpy(buffer, str);
-
- /* Get a pointer to 'buffer' */
- indptr = buffer;
-
- /* NULL-terminate the 'Algo' field */
- *(indptr + (ALGO_SIZE - 1)) = NULL;
-
- /* Copy the 'Algo' field to first array */
- strcpy(algo, indptr);
-
- /* Increment string ptr. to 'KeyID' field */
- indptr += ALGO_SIZE;
-
- /* NULL-terminate the 'KeyID' field */
- *(indptr + (KEYID_SIZE - 1)) = NULL;
-
- /* Copy the 'KeyID' field to second array */
- strcpy(keyID, indptr);
-
- /* Increment string ptr. to 'Created' field */
- indptr += KEYID_SIZE;
-
- /* NULL-terminate the 'Created' field */
- *(indptr + (CREATED_SIZE - 1)) = NULL;
-
- /* Copy the 'Created' field to third array */
- strcpy(created, indptr);
-
- /* Increment string ptr. to 'UserID' field */
- indptr += CREATED_SIZE;
-
- /* 'UserID' field is already NULL-terminated (EOL)
- ** Copy the 'UserID' field to fourth array
- */
- strcpy(userID, indptr);
-
- array[0] = algo;
- array[1] = keyID;
- array[2] = created;
- array[3] = userID;
- }
- else
- {
- /*
- ** No text in the string...
- ** A signal by the "listview" gadget that tells us
- ** to re-initialise the title info for the columns.
- */
- array[0] = "\33b\33uAlgo";
- array[1] = "\33b\33uKeyID";
- array[2] = "\33b\33uCreated";
- array[3] = "\33b\33uUserID";
- }
- }
-
- /* A Hook structure used by the "listview" gadget. */
- static const struct Hook DisplayLI_TextHook =
- {
- { NULL,NULL },
- (VOID *)DisplayLI_TextFunc,
- NULL,NULL
- };
-
- /*
- ** Generate the MUI GUI for the user.
- */
- static struct ObjApp_SelKey *
- CreateSelectPGPKApp(char *wintitle, ULONG multiselect)
- {
- struct ObjApp_SelKey *ObjectApp;
-
- APTR GROUP_KeyLister, GR_BT_SEL_OKCAN;
-
- if (!(ObjectApp = AllocVec(sizeof(struct ObjApp_SelKey),MEMF_PUBLIC|MEMF_CLEAR)))
- return(NULL);
-
- ObjectApp->LV_KEYLISTVIEW = ListObject,
- MUIA_Frame, MUIV_Frame_InputList,
- MUIA_List_DisplayHook, &DisplayLI_TextHook,
- MUIA_List_Format, "P=\33l BAR,P=\33l BAR,P=\33l BAR,P=\33l",
- MUIA_List_SourceArray, keystable,
- MUIA_List_Title, TRUE,
- End;
-
- ObjectApp->LV_KEYLISTVIEW = ListviewObject,
- MUIA_Listview_MultiSelect, multiselect,
- MUIA_Listview_List, ObjectApp->LV_KEYLISTVIEW,
- End;
-
- ObjectApp->BT_SEL_OK = SimpleButton("Ok");
-
- ObjectApp->BT_SEL_CANCEL = SimpleButton("Cancel");
-
- GR_BT_SEL_OKCAN = GroupObject,
- MUIA_Group_Horiz, TRUE,
- Child, ObjectApp->BT_SEL_OK,
- Child, ObjectApp->BT_SEL_CANCEL,
- End;
-
- GROUP_KeyLister = GroupObject,
- MUIA_Frame, MUIV_Frame_Group,
- MUIA_FrameTitle, "Choose a key",
- Child, ObjectApp->LV_KEYLISTVIEW,
- Child, GR_BT_SEL_OKCAN,
- End;
-
- ObjectApp->WI_SelectPGP5Key = WindowObject,
- MUIA_Window_Title, wintitle,
- MUIA_Window_CloseGadget, FALSE,
- MUIA_Window_ID, MAKE_ID('W', 'I', 'N', '2'),
- MUIA_Window_NoMenus, TRUE,
- WindowContents, GROUP_KeyLister,
- End;
-
- ObjectApp->App = ApplicationObject,
- MUIA_Application_Base, "PGP5GUI-KEYLIST",
- MUIA_Application_Title, "PGP5GUI-KEYLIST",
- SubWindow, ObjectApp->WI_SelectPGP5Key,
- End;
-
-
- if (!ObjectApp->App)
- {
- FreeVec(ObjectApp);
- return(NULL);
- }
-
- DoMethod(ObjectApp->BT_SEL_OK,
- MUIM_Notify, MUIA_Pressed, FALSE,
- ObjectApp->App,
- 2,
- MUIM_Application_ReturnID, SEL_OK
- );
-
- DoMethod(ObjectApp->BT_SEL_CANCEL,
- MUIM_Notify, MUIA_Pressed, FALSE,
- ObjectApp->App,
- 2,
- MUIM_Application_ReturnID, SEL_CANCEL
- );
-
- DoMethod(ObjectApp->WI_SelectPGP5Key,
- MUIM_Window_SetCycleChain, ObjectApp->LV_KEYLISTVIEW,
- ObjectApp->BT_SEL_OK,
- ObjectApp->BT_SEL_CANCEL,
- 0
- );
-
- set(ObjectApp->WI_SelectPGP5Key, MUIA_Window_Open, TRUE);
-
- return(ObjectApp);
- }
-
- int
- SelectPGPKey(struct ObjApp *prevApp, char *selected[], char *winname, ULONG multiselect)
- {
- struct ObjApp_SelKey *App; /* Object */
- BOOL running = TRUE;
- ULONG signal;
-
- char *fib = 0;
- char keyID[16], keyinfo[BUFFER_SIZE];
-
- int retval = 0, i;
-
- LONG id = MUIV_List_NextSelected_Start;
-
- set(prevApp->TX_Status, MUIA_Text_Contents, "\33cWaiting for key choice");
-
- /* Make the parent window go to sleep */
- set(prevApp->WI_Main, MUIA_Window_Sleep, TRUE);
-
- /* Create Object */
- if (!(App = CreateSelectPGPKApp(winname, multiselect)))
- {
- PrintFault(IoErr(), "Couldn't create SelectPGPK MUI");
- return(20);
- }
-
- while (running)
- {
- switch (DoMethod(App->App,MUIM_Application_Input,&signal))
- {
- case SEL_CANCEL:
- /*
- ** User pressed 'Cancel' button!
- ** Signal to break out of this loop.
- */
- running = FALSE;
- retval = -1;
- break;
-
- case SEL_OK:
- /*
- ** User pressed 'OK'.
- ** Return selected entry (if any) in 'selected' array.
- */
- for (i = 0; i < 256; i++)
- {
- /* Check for next selected entry */
- DoMethod(App->LV_KEYLISTVIEW, MUIM_List_NextSelected, &id);
-
- /*
- ** No more entries selected (end of list)???
- ** Break out of loop.
- */
- if (id == MUIV_List_NextSelected_End)
- break;
-
- /* Get entry that is selected */
- DoMethod(App->LV_KEYLISTVIEW, MUIM_List_GetEntry, id, &fib);
-
- /* Get a copy of the line into 'keyinfo' */
- strcpy(keyinfo, fib);
-
- /* Terminate the end of the keyID info */
- *(keyinfo + ((KEYID_SIZE + ALGO_SIZE) - 1)) = NULL;
-
- /* Get the keyID info into 'keyID' */
- strcpy(keyID, keyinfo + ALGO_SIZE);
-
- /* If line is not empty, copy line to allocated memory */
- if (strlen(keyID))
- strcpy(selected[i], keyID);
- else
- break; /* Protect against any weird future bugs ;-) */
- }
-
- *selected[i] = '\0';
-
- /* Signal to break out of this loop. */
- running = FALSE;
- break;
-
- default:
- break;
- }
-
- if (running && signal)
- Wait(signal);
- }
-
- /* De-allocate and free up the resources used by the MUI GUI */
- MUI_DisposeObject(App->App);
- FreeVec(App);
-
- /* Make the parent window wake up */
- set(prevApp->WI_Main, MUIA_Window_Sleep, FALSE);
-
- /* Wake up the parent window */
- set(prevApp->WI_Main, MUIA_Window_Activate, TRUE);
-
- set(prevApp->TX_Status, MUIA_Text_Contents, ReadyMSG);
-
- /*
- ** Return flag to caller:
- ** 0 = OK, -1 = Cancel, 20 = Failed MUI App
- */
- return(retval);
- }
-